<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<script type="text/javascript" charset="UTF-8" src="<c-rt:url value="/js/yaodian100_mid_soaddr.js"/>"></script>
${pu:reqSet('orderProduct', pu:get('com.yaodian100.ec.order.entity.OrderProduct', pu:toLong(param.orderProdId))) }
${pu:reqSet('order', pu:get('com.yaodian100.ec.order.entity.Orders', orderProduct.orderId)) }
<style>
.tableAlignLeft td{
	text-align:left;
}
</style>
<h1>
退货单(订单编号：${order.orderId })
</h1>
<script>
$(function(){
		//主商品
		$('.qtys0').each(function(){
				$(this).change(function(){
					var value=$(this).attr('value');
					$('.qtys0').each(function(){
						$(this).attr('value', value);
					});
					$('.qtys2').each(function(){
						$(this).attr('value', value);
					});
					$('.qtys3').each(function(){
						
						if($(this).attr('value')<value){
							$(this).attr('value', value);
						}
					});
				});
		});
		//预购
		$('.qtys1').each(function(){
				$(this).change(function(){
					var value=$(this).attr('value');
					$('.qtys1').each(function(){
						$(this).attr('value', value);
					});
					$('.qtys2').each(function(){
						$(this).attr('value', value);
					});
					$('.qtys3').each(function(){
						
						if($(this).attr('value')<value){
							$(this).attr('value', value);
						}
					});
				});
		});
		//赠品
		$('.qtys2').each(function(){
			$(this).change(function(){
				var theValue='';
				if($('.qtys0').length>0){
					$('.qtys0').each(function(){
						theValue=$(this).attr('value');
					});
				}else{
					theValue=$(this).attr('value');
				}
					$(this).attr('value', theValue);
				});
		});
		//加购
		$('.qtys3').each(function(){
			$(this).change(function(){
				var theValue='';
				$('.qtys0').each(function(){
					theValue=$(this).attr('value');
				});
				if(theValue>$(this).attr('value')){
					$(this).attr('value', theValue);
				}
			});
		});
		//活动
		$('.qtys4').each(function(){
			$(this).change(function(){
				var theValue=$(this).attr('value');
				$('.qtys4').each(function(){
					$(this).attr('value', theValue);
				});
				$('.qtys6').each(function(){
					$(this).attr('value', theValue);
				});
			});
		});
		//满额购
		$('.qtys5').each(function(){
			$(this).change(function(){
				var theValue=$(this).attr('value');
				$('.qtys5').each(function(){
					$(this).attr('value', theValue);
				});
			});
		});
		//任选
		$('.qtys6').each(function(){
			$(this).change(function(){
				var myName = $(this).attr('name');
				//order detail 要可以個別退貨
				if (myName == 'mainQty') {
					var theValue=$(this).attr('value');
					$('.qtys6').each(function(){
						$(this).attr('value', theValue);
					});
				}
			});
		});
		//精品
		$('.qtys7').each(function(){
				$(this).change(function(){
					var value=$(this).attr('value');
					$('.qtys7').each(function(){
						$(this).attr('value', value);
					});
					$('.qtys2').each(function(){
						$(this).attr('value', value);
					});
					$('.qtys3').each(function(){
						
						if($(this).attr('value')<value){
							$(this).attr('value', value);
						}
					});
				});
		});
});
function checkForm(){
	var returnCount=0;
	$('.qtys0').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys1').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys2').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys3').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys4').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys5').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys6').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys7').each(function(){
		returnCount+=$(this).attr('value');
	});
	
	var errorMessage="";
	var error=0;	
//	if(returnCount==0){
//		errorMessage+='请选择退货商品数数量\r\n';
//	}
	if(returnCount<2){
		errorMessage+='请选择退货商品数数量\r\n';
	}
	if(returnCount>1&&returnCount<11){
		errorMessage+='请选择退货商品明细数量\r\n';
	}
	
	$('.reason').each(function(){
		if($(this).attr('value')==''){
			error++;
		}
	});
	if(error>0){
		errorMessage+="请选择退货原因\r\n";
	}
	error=0;
	
	$('.description').each(function(){
		if($(this).attr('value')==''){
			error++;
		}
	});
	if(error>0){
		errorMessage+="请填写退货原因\r\n";
	}
	error=0;

	$('.accessaryDescription').each(function(){
		if($(this).attr('value')==''){
			error++;
		}
	});
	if(error>0){
		errorMessage+="请填写配件赠品状态\r\n";
	}
	if($('#receiverName').attr('value')==''){
		errorMessage+="请填联络人姓名\r\n";
	}
	if($('#province').attr('value')==''
		|| $('#city').attr('value')==''
		|| $('#district').attr('value')==''
		|| $('#receiverAddr').attr('value')==''
		|| $('#receiverZip').attr('value')==''){
		errorMessage+="请填联络地址\r\n";
	}

	if($('#receiverMobile').attr('value')==''){
		if($('#receiverPhoneArea').attr('value')==''
			|| $('#receiverPhone').attr('value')==''
			){
			
			errorMessage+="请填手机电话或固定电话\r\n";
		}else{
			if(
					$('#receiverPhone').attr('value').length<5
					|| $('#receiverPhone').attr('value').length>10
					|| isNaN($('#receiverPhone').attr('value'))
				){
				
				errorMessage+="固定电话为长度5～10的数字\r\n";
			}
		}
		
	}else if(isNaN($('#receiverMobile').attr('value')) || $('#receiverMobile').attr('value').length>11){
		errorMessage+="手机电话为长度小于11的数字\r\n";
	}
	

	if(errorMessage!=''){
		alert(errorMessage);
	}
	else{
		document.returnForm.submit();
	}
}
</script>

<form name="returnForm" method="post" action="/ecadmin/serviceOrder/returnProduct.do">
<input type="hidden" name="paymentTp" value="${order.paymentTp }"/>
<input type="hidden" name="orderId" id="orderId" value="${order.orderId }"/>
<input type="hidden" name="memberId" value="${order.memberId }"/>
<input type="hidden" name="orderProdId" value="${orderProduct.orderProdId }"/>
<s:hidden name="oldServiceId" />
<s:hidden name="orderDetailId" />
<table class="tb-1 tableAlignLeft">
<thead>
<tr>
	<th>orderProdId</th><th>商品名称</th><th>明细</th>
</tr>
</thead>
<tbody>
		<tr>
			<td>${orderProduct.orderProdId }<input type="hidden" name="orderProdId" value="${orderProduct.orderProdId }"/></td>
			<td>${orderProduct.prodName } x 
			<select name="mainQty" class="qtys${orderProduct.prodTp }">
			<c-rt:forEach begin="0" end="${orderProduct.qty}" varStatus="index">
			<option value="${index.index }">${index.index }</option>
			</c-rt:forEach>
			</select>
			</td>
			<td>
				<table>
				<%-- 讓 n 選 m 可以個自單獨退貨 --%>
				<c-rt:choose>
					<c-rt:when test="${!empty orderProductDetailList}">
						<c-rt:set var="orderProductDetailListToReturn" value="${orderProductDetailList}"></c-rt:set>
					</c-rt:when>
					<c-rt:otherwise>
						<c-rt:set var="orderProductDetailListToReturn" value="${orderProduct.orderProductDetail}"></c-rt:set>
					</c-rt:otherwise>
				</c-rt:choose>
				
				<c-rt:forEach items="${orderProductDetailListToReturn}" var="opd">
					<s:set name="orderDetailId">
						${opd.orderDetailId}
					</s:set>
					<s:if test="%{serviceOrderService.isOrderDetailReturnableChangable(#orderDetailId)}">
						<tr>
							<td>
								<c-rt:if test="${opd.detailTp=='0'}">
									<c-rt:set var="detailTp" scope="request" value="0"/>
									<span class="type-0">主商品</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='1'}">
									<c-rt:set var="detailTp" scope="request" value="1"/>
									<span class="type-1">预购</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='2'}">
									<c-rt:set var="detailTp" scope="request" value="2"/>
									<span class="type-2">赠品</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='3'}">
									<c-rt:set var="detailTp" scope="request" value="3"/>
									<span class="type-3">加购</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='4'}">
									<c-rt:set var="detailTp" scope="request" value="4"/>
									<span class="type-4">活动</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='5'}">
									<c-rt:set var="detailTp" scope="request" value="5"/>
									<span class="type-5">满额购</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='6'}">
									<c-rt:set var="detailTp" scope="request" value="6"/>
									<span class="type-6">任选</span>
								</c-rt:if>
								<c-rt:if test="${opd.detailTp=='7'}">
									<c-rt:set var="detailTp" scope="request" value="7"/>
									<span class="type-7">精品</span>
								</c-rt:if>
								
								${opd.prodName }[${opd.prodSpecName }]x
								<input type="hidden" name="prodSpecIds" value="${opd.prodSpecId }"/>
								
								<select name="qtys" class="qtys${detailTp }">
									<c-rt:forEach begin="0" end="${opd.qty}" varStatus="index">
										<option value="${index.index }">${index.index }</option>
									</c-rt:forEach>
								</select>
							</td>
						</tr>
					</s:if>
				</c-rt:forEach>
				</table>
			</td>
			
		</tr>
		
		
</tbody>
</table>

<table class="tb-1 tableAlignLeft">
	<tr>
		<th>
		退货原因
		</th>
		<td>
		 <select name="reason" class="reason">
	          <option value="">请选择原因</option>
	          <option value="订购错误">订购错误</option>
	          <option value="商品发错">商品发错</option>
	          <option value="商品或外包装破损">商品或外包装破损</option>
	          <option value="商品不如预期">商品不如预期</option>
	          <option value="商品属性不符">商品属性不符</option>
	          <option value="价格比较贵">价格比较贵</option>
	          <option value="与介绍不符">与介绍不符</option>
	          <option value="改买其他款式">改买其他款式</option>
	          <option value="商品未如期收到">商品未如期收到</option>
	          <option value="不会使用">不会使用</option>
	          <option value="其他">其他</option>
	          </select>
		</td>
	</tr>
	<tr>
		<th>
		退货原因描述
		</th>
		<td>
		<textarea name="description" class="description" rows="5" cols="100"></textarea>
		</td>
	</tr>
	<tr>
		<th>
		配件赠品状态
		</th>
		<td>
		<input class="return-txtfild accessaryDescription" type="text" name="accessaryDescription" value="" size="100"/>
		</td>
	</tr>
	<tr>
		<th>
		姓名
		</th>
		<td>
		<input type="text" name="receiverName" id="receiverName" value="${order.receiverName }" size="10" />
		</td>
	</tr>
	<tr>
		<th>联络地址</th>
		<td>
		<select id="province" name="receiverProvince" class="c-prov"><option value="">== 选择省 ==</option>
			<c-rt:forEach items="${provincesMap}" var="province" >
				<option value="${province.key}">${province.key}</option>
			</c-rt:forEach>
		</select> 
              市：<select name="receiverCity" id="city"> 
                <option value="">== 选择城市 ==</option>
              </select> 
              区：<select name="receiverArea" id="district"> 
                <option value="">== 选择地区 ==</option>
              </select> 
              <br /> 
              邮编：<input type="text" name="receiverZip" id="receiverZip" value="${order.receiverZip}"/>
              街道：<input size="50" name="receiverAddr" id="receiverAddr" value="${order.receiverAddr }" /> 
		</td>
	</tr>
	<tr>
		<th>手机电话</th>
		<td><input type="text" name="receiverMobile" id="receiverMobile" value="${order.receiverMobile }" size="10" /></td>
	</tr>
	<tr>
		<th>固定电话</th>
		<td>
			<input type="text" name="receiverPhoneArea" id="receiverPhoneArea" value="${order.receiverPhoneArea }" size="3" />-<input type="text" name="receiverPhone" id="receiverPhone" value="${order.receiverPhone }" size="7" />-分机<input type="text" name="receiverExt" id="receiverExt" value="${order.receiverExt }" size="4" />
		</td>
	</tr>
	<tr>
		<th></th>
		<td>
		<input type="button" value="送出" onclick="checkForm()"/>
		<input type="hidden" value="${order.receiverProvince}" id="receiverProvince"/>
		<input type="hidden" value="${order.receiverCity}" id="receiverCity"/>
		<input type="hidden" value="${order.receiverArea}" id="receiverArea"/>
		<input type="reset" value="重置"/>
		</td>
	</tr>
</table>
</form>